﻿@using OBUCare.Core.Models;
@using OBUCare.Core.Models;
@using OBUCare.Web.Models;
@using OBUCare.Web.Infrastructure;
@model REPAIR_ORDERS
@{
    ViewBag.Title = "标签维修单";
    var faultModel = ViewBag.FaultViewModel as IEnumerable<ExtendedSelectListItem<DICT_TYPE_VALUE>>;

    var dateNow = DateTime.Now.ToString("yyyy-MM-dd");
}
<link href="../../Content/tableCss.css" rel="stylesheet" type="text/css" />
<div>
</div>
<table>
    <tr>
        <td>
            <font color="#4fb82c" class="txt14_24">标签维修单录入&gt;&gt;</font>
        </td>
    </tr>
    <tr>
        <td>
            标签号：@Html.TextBox("txtOUBNo")&nbsp;&nbsp;&nbsp;<input type="button" value="            " id="btnLoadOBU" style="background-image: url(@Url.Content("~/Content/images/button_search.gif")); width:150;height:30"/>
        </td>
    </tr>
    <tr>
        <td>
            @using (Html.BeginForm("NewOrder", "RepairOrders", FormMethod.Post, new { @id = "form_id" }))
            {
                @Html.ValidationSummary(true)
    
                <div id="divObuContainer" style="display: none;">
                    <br />
                    <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                    <br />
                    <center>
                        <h1>
                            基本信息</h1>
                    </center>
                    <br />
                    <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                    <br />
                    <!--动态加载标签基本信息的div容器-->
                    <div id="divObubaseInfoContainer" style="width: 100%">
                    </div>
                    <div id="divContent">
                        <table>
                            <tr>
                                <td width="20%">
                                </td>
                                <td width="30%">
                                </td>
                                <td width="20%">
                                </td>
                                <td width="30%" align="right">
                                    <span style="color: Red; font-size: small;">标"*"为必填项</span>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    @Html.LabelFor(model => model.MOBILE_TEL_NO)
                                </td>
                                <td>
                                    @Html.EditorFor(model => model.MOBILE_TEL_NO)&nbsp<span style="color: Red;">*</span>
                                    @Html.ValidationMessageFor(model => model.MOBILE_TEL_NO)
                                </td>
                                <td>
                                    @Html.LabelFor(model => model.TEL_NO)
                                </td>
                                <td>
                                    @Html.EditorFor(model => model.TEL_NO)
                                    @Html.ValidationMessageFor(model => model.TEL_NO)
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    @Html.LabelFor(model => model.MAX_PRICE)
                                </td>
                                <td>
                                    @Html.EditorFor(model => model.MAX_PRICE)&nbsp<span style="color: Red;">*</span>
                                    @Html.ValidationMessageFor(model => model.MAX_PRICE)
                                </td>
                                <td>
                                    @Html.LabelFor(model => model.REPORTER)
                                </td>
                                <td>
                                    @Html.EditorFor(model => model.REPORTER)&nbsp<span style="color: Red;">*</span>
                                    @Html.ValidationMessageFor(model => model.REPORTER)
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4">
                                    <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    @Html.Label("lblOrderFalut", "故障描述")
                                    @* @Html.LabelFor(model => model.OrderFalut)
                        @Html.ValidationMessageFor(model => model.OrderFalut)*@ @*@Html.HiddenFor(model => model.OrderFalut, new { width = "0px" })*@
                                </td>
                                <td colspan="3">
                                    @Html.Partial("_FaultCheckBoxList", faultModel)
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4">
                                    <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    @Html.LabelFor(model => model.FACE_STATUS)
                                </td>
                                <td colspan="3">
                                    @Html.RadioButtonFor(model => model.FACE_STATUS, false, new { @id = "FACE_STATUS0", @checked = "checked" })
                                    @Html.Label("FACE_STATUS0", "外观完好")
                                    @Html.RadioButtonFor(model => model.FACE_STATUS, true, new { @id = "FACE_STATUS1" })
                                    @Html.Label("FACE_STATUS1", "外观有故障")
                                    @Html.ValidationMessageFor(model => model.FACE_STATUS)
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4">
                                    <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    @Html.LabelFor(model => model.REPAIR_TYPE)
                                </td>
                                <td colspan="3">
                                    @*@Html.EditorFor(model => model.REPAIR_TYPE)*@
                                    @Html.Partial("_RepairType", ViewBag.RepairTypeViewModel as IEnumerable<ExtendedSelectListItem<REPAIR_TYPE>>)
                                    @Html.ValidationMessageFor(model => model.REPAIR_TYPE)
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4">
                                    <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    @Html.Label("isNeedSpareObu", "是否需要备用标签:")
                                </td>
                                <td colspan="3">
                                    @Html.RadioButton("radisNeedSpareObu", "1", new { @id = "radisNeedSpareObuY" })
                                    @Html.Label("radisNeedSpareObuY", "是")
                                    @Html.RadioButton("radisNeedSpareObu", "0", true, new { @id = "radisNeedSpareObuN" })
                                    @Html.Label("radisNeedSpareObuY", "否")
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4">
                                    <table id="tbSpare" style="display: none">
                                        <tr>
                                            <td colspan="4">
                                                <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                @Html.LabelFor(model => model.SPARE_OBU_NO)
                                            </td>
                                            <td>
                                                @Html.EditorFor(model => model.SPARE_OBU_NO)
                                                @Html.ValidationMessageFor(model => model.SPARE_OBU_NO)
                                            </td>
                                            <td>
                                                @Html.LabelFor(model => model.SPARE_OBU_PRICE)
                                            </td>
                                            <td>
                                                @Html.EditorFor(model => model.SPARE_OBU_PRICE)<span>(元)</span>
                                                @Html.ValidationMessageFor(model => model.SPARE_OBU_PRICE)
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                @Html.LabelFor(model => model.SPARE_OBU_ISSUE_DATE)
                                            </td>
                                            <td>
                                                @*@Html.EditorFor(model => model.SPARE_OBU_ISSUE_DATE)*@
                                                @Html.Telerik().DatePickerFor(model => model.SPARE_OBU_ISSUE_DATE).OpenOnFocus(true).ShowButton(false).Value(DateTime.Now.ToString("yyyy-MM-dd")).Format("yyyy-MM-dd")
                                                @Html.ValidationMessageFor(model => model.SPARE_OBU_ISSUE_DATE)
                                            </td>
                                            <td>
                                            </td>
                                            <td>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4">
                                    <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    @Html.LabelFor(model => model.REPORT_DATE)
                                </td>
                                <td>
                                    @Html.Telerik().DatePickerFor(model => model.REPORT_DATE).OpenOnFocus(true).ShowButton(false).Value(DateTime.Now.ToString("yyyy-MM-dd")).Format("yyyy-MM-dd")&nbsp<span
                                        style="color: Red;">*</span>
                                    @Html.ValidationMessageFor(model => model.REPORT_DATE)
                                </td>
                                <td>
                                </td>
                                <td>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <br />
                    <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                    <br />
                    <div>
                        <input type="button" id="submit" value=" " style="background-image: url(@Url.Content("~/Content/images/button_up.gif")); width:200;height:30" />
                    </div>
                </div>
            }
        </td>
    </tr>
</table>
<div id="divPrintContainer">
</div>
<script type="text/javascript">

    $(function () {
        $('#txtOUBNo').focus();
        $('#txtOUBNo').keypress(function (e) {
            var code = e.keyCode ? e.keyCode : e.which;
            var value = $('#txtOUBNo').val();
            value = $.trim(value);
            if (code == 13 && (!value.StringIsNullOrEmpty())) {
                loadObuInfoControl(value);
            }
            else if (value.StringIsNullOrEmpty()) {
                $('#divObuContainer').hide();
            }
        });

        $('#btnLoadOBU').click(function () {
            var value = $('#txtOUBNo').val();
            value = $.trim(value);
            //            $(':input', '#form_id')
            //            .not(':button,:submit,:reset,:hidden')   //将myform表单中input元素type为button、submit、reset、hidden排除
            //            .val('');
            document.getElementById("form_id").reset();
            loadObuInfoControl(value);
            $("#SPARE_OBU_ISSUE_DATE").val("@dateNow");
            $("#SPARE_OBU_PRICE").val("300");
            $("#REPORT_DATE").val("@dateNow");
        });


        $("#radisNeedSpareObuN").click(function () {
            $("#SPARE_OBU_ISSUE_DATE").val("");
            $("#SPARE_OBU_PRICE").val("");
            $("#SPARE_OBU_NO").val("");
            $("#tbSpare").attr("style", "display:none");
        })
        $("#radisNeedSpareObuY").click(function () {
            $("#SPARE_OBU_ISSUE_DATE").val("@dateNow");
            $("#SPARE_OBU_PRICE").val("300");
            $("#tbSpare").attr("style", "display:inline");
        })

        $("#submit").click(function () {
            //debugger;
            var labels = $("label[name=lab]");
            for (var i = 0; i < labels.length; i++) {
                var faultContent = $(labels[i]).html();

                if (faultContent == '其它') {
                    var faultFor = $(labels[i]).attr("for");
                    var checked = $("#" + faultFor).attr("checked");
                    var orderFaultReMark = $("#orderFaultReMark").val();
                    if (checked == "checked" && orderFaultReMark.StringIsNullOrEmpty()) {
                        alert("必须填写故障描述！"); return false;
                    }

                }
            }

            var labelstype = $("label[name=type]");
            for (var i = 0; i < labelstype.length; i++) {
                var typeContent = $(labelstype[i]).html();

                if (typeContent == '其它') {
                    var typeFor = $(labelstype[i]).attr("for");
                    var checked = $("#" + typeFor).attr("checked");
                    var orderTypeReMark = $("#REPAIRED_COMMENT").val();
                    if (checked == "checked" && orderTypeReMark.StringIsNullOrEmpty()) {
                        alert("必须填写维修类型描述！"); return false;
                    }

                }
            }

            var s_obu_price = $("#SPARE_OBU_PRICE").val()
            var s_obu_issue_date = $("#SPARE_OBU_ISSUE_DATE").val();
            var chk = $("#radisNeedSpareObuY").attr("checked");
            if (chk == "checked") {
                if (s_obu_price.length == 0) {
                    alert("请输入备用标签押金！"); return false;
                }
                else if (s_obu_issue_date.length == 0) {
                    alert("请输入备用标签安装日期！"); return false;
                }
            }

            //判断厂商和型号
            var supplierValue = $('#Supplier').val();
            var specValue = $('#Specs').val();
            if (supplierValue == "请选择" || specValue == "请选择" ||specValue=="无") {
                alert("请选择厂商或型号");
                return false;
            }

            var form = $("#form_id");
            dataString = form.serialize();
            $.ajax({
                type: "POST",
                url: form.attr('action'),
                data: dataString,
                cache: false,
                dataType: "json",
                success: function (data) {
                    var url = "";
                    if (data.userNO != "")
                        url = "/Transaction/Index/?orderUserNo=" + data.userNO;
                    else
                        url = "/RepairOrders/List/";

                    if (data.Success) {
                        if (confirm("提交成功，是否打印?")) {
                            //printOrder(data.id, url);
                            //window.location.href = "/RepairOrders/Print/" + data.id + "?userNO=" + data.userNO;
                            window.open("/RepairOrders/Print/" + data.id + "?userNO=" + data.userNO);
                        }
                        window.location.href = url;
                    }
                    else {
                        alert('提交失败：' + data.ErrorMsg)
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    var err = XMLHttpRequest + "<br />" + textStatus + "<br />" + errorThrown;
                    alert(err);
                }
            });

        })

    });

    function getDate(separator) {
        var d, s = "";
        d = new Date();
        s += d.getFullYear() + separator;
        s += (d.getMonth() + 1) + separator;
        s += d.getDate();
        return s;
    }

    //动态加载基本信息的局部视图
    function loadObuInfoControl(id) {
        var url = '/RepairOrders/ObuBaseInfoControl/' + id;
        if (id.length == 0) {
            alert("请输入标签号！");
        }
        else {
            $.post("/RepairOrders/CheckStatus/", { id: id }, function (data) {
                var message = data.message;
                if (message == "repaired") {
                    $('#divObuContainer').hide();
                    alert("标签维修未结束，不允许录入");
                }
                else {
                    $('#divObubaseInfoContainer').load(url, function (response, status) {
                        //debugger;
                        if (message == "success" && response != "false") {
                            $('#divObuContainer').show();
                            var d = $("#CheckDate").attr("Date");
                            if (d == 1) {
                                $("#REPAIR_TYPE3").attr("checked", "checked");
                            }
                        }
                        else {
                            $('#divObuContainer').hide();
                            alert("标签处于非流通状态或者不存在，不允许维修");
                        }
                    })
                }
            })

        }
    }


    //动态加载打印页面，并打印
    function printOrder(id, url) {
        var purl = '/RepairOrders/Print/' + id;

        $('#divPrintContainer').load(purl, function (response, status) {
            debugger
            //alert(status);
            if (status == "success") {
                $('#divPrintContainer').show();
                printpage('divPrintContainer');
                //alert("打印成功");
                //window.location.href = url;
            }
            else {
                alert("打印失败");
            }
        })

    }

</script>
@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}
